<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="stylesheet" type="text/css" href="__STATIC__/index/css/style.css" />
	<script type="text/javascript" src="__STATIC__/index/js/rem.js"></script>
	<title>地址管理</title>
</head>
<body class="geryBg">
  <div class="address">
  	 <ul class="address_list">
		 {foreach $db as $vo}
  	 	<li togy="{$vo.id}">
  	 	  <a href="saveAddress?id={$vo.id}">
  	 		<div class="add">
  	 			<div class="add_content">
  	 				<div class="add_concat clear smoth">
  	 					<p class="fl">收货人: <em>{$vo.name}</em></p>
  	 					<p class="fr">{$vo.phone}</p>
  	 				</div>
  	 				<p class="normall-text smoth loca">
						<img class="location" src="__STATIC__/index/img/icon-add.png" />
						收货地址 : <em>{$vo.area}{$vo.address}</em>
						<img class="arrow" src="__STATIC__/index/img/arrow-gery.png" />
					</p>
  	 			</div> 	 			
  	 		</div>
  	 	   </a>
  	 		<div class="default_address">
  	 			<i class="check {if $vo.status==2}checked{/if}" togy="{$vo.id}"></i>
  	 			<p class="cutgery super-text">默认地址</p>
  	 			<img class="del" src="__STATIC__/index/img/icon-delete.png" />
  	 		</div>
  	 	</li>
  	 	{/foreach}
  	 </ul>
     <!--新增地址按钮-->
     <div class="add_btn">
     	<button><em>+</em><span>新增地址</span></button>
     </div> 	 
  </div>
<!--弹窗删除地址-->
<div class="cart_pop">
   <div class="pop_msg">
      <img class="pop_close" src="__STATIC__/index/img/icon-close.png" onclick="hideTips('.cart_pop')" />
      <p class="text-center super-text smoth bold">确定要删除该地址吗?</p>
      <div class="pop_btn">
        <button class="cancel" onclick="hideTips('.cart_pop')">取消</button>
        <button class="ensure">确定</button>
      </div>
   </div>
</div>
<script type="text/javascript" src="__STATIC__/index/js/jquery-1.11.2.min.js"></script>
  <script type="text/javascript" src="__STATIC__/index/js/layer/mobile/layer.js"></script>
  <script type="text/javascript">
	//弹出框
	function showTips(classname){
		return $(classname).show()
	}
	function hideTips(classname){
		return $(classname).hide()
	}
	//点击删除图标
	var index;
	var int;
	$('.del').on('click',function(){
		showTips('.cart_pop')
		index = $(this).parents('li').index();
		int = $(this).parents('li').attr('togy');
	})
	//点击确定删除
	$('.ensure').on('click',function(){
        hideTips('.cart_pop')
        //遍历删除
        $('.address_list li').eq(index).remove();
        $.ajax({
			url:"delAddress",
			type:"post",
			data:{id:int},
			success:function (res) {
                if(res=='ok'){
                    layer.open({
                        content:'删除成功',
                        skin:'msg',
                        time:2
                    })
                }
            }
		})
	})
	//选择默认地址
	$('.check').on('click',function(){
		$(this).addClass('checked').parents('li').siblings().find('.check').removeClass('checked');
		var id =  $(this).attr('togy');
		$.ajax({
			url:"defaultAddress",
			type:"POST",
			data:{id:id},
			success:function (res) {
				if(res=='ok'){
                    layer.open({
                        content:'设置成功',
                        skin:'msg',
                        time:2
                    })
				}
            }
		})
	})
	//跳转新增地址
	$('.add_btn').on('click',function(){
		window.location.href = 'saveAddress'
	})
</script>
</body>
</html>